package com.java1412.order.controller;

import com.java1412.common.entity.Goods;
import com.java1412.order.service.GoodsService;
import org.aspectj.weaver.ast.Var;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 订单接口
 *
 * @author java1412
 * @since 2024-04-23 16:51:31
 */
@RestController
@RequestMapping("/api/v1/goods_order")
public class OrderController {

    // 注入restTemplate
//    @Resource
//    private RestTemplate restTemplate;
//
//    @RequestMapping("/getGoods")
//    public Object save(Integer goodsId) {
//        // Goods goods = restTemplate.getForObject("http://localhost:6001/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
//        // 使用注册中心的应用名称来进行远程调用
//        Goods goods = restTemplate.getForObject("http://mall-goods/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
//        return goods;
//    }

    // 通过feign来远程调用商品微服务
    @Resource
    private GoodsService goodsService;

    @RequestMapping("/getGoodsByFeign")
    public Object getGoodsByFeign(Integer goodsId) {
        Object o = goodsService.findByGoodsId(goodsId);
        return o;
    }

    @RequestMapping(value = "/getClusterName")
    public Object findClusterName() {
        // 循环调用10次
        for (int i = 0; i < 10; i++) {
            String ret = goodsService.findClusterName();
            System.out.println(ret);
        }
        return "ok";
    }
}
